﻿using System;
using System.Configuration;
using System.Threading.Tasks;

namespace AisinGioro.Notify
{
    public interface INotify
    {
        bool Enabled { get; }
        Task<string> SendMsg(string message);
    }

    public abstract class NotifyBase : ConfigurationSection, INotify
    {
        public virtual bool Enabled
        {
            get
            {
                if (string.IsNullOrEmpty(ConfigurationManager.AppSettings["NotifyEnabled"]))
                    return false;

                return Boolean.Parse(ConfigurationManager.AppSettings["NotifyEnabled"]);
            }
        }

        public abstract Task<string> SendMsg(string message);

        private static INotify _instance = null;
        public static INotify GetInstance()
        {
            if (_instance == null)
                _instance = (INotify)ConfigurationManager.GetSection("notify");            

            return _instance;
        }
    }
}
